package com.zzyl.mapper;

import com.github.pagehelper.Page;
import com.zzyl.dto.UserDto;
import com.zzyl.dto.UserPasswordDto;
import com.zzyl.entity.User;
import com.zzyl.vo.UserVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {

    int deleteByPrimaryKey(Long id);

    int insert(User record);

    int insertSelective(User record);

    User selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);

    int batchInsert(@Param("list") List<User> list);

    //分页条件
    List<User> selectPage(UserDto userDto);


    //姓名是否存在
    @Select("select count(1) from sys_user where real_name=#{realName}")
    Long selectByName(String realName);

    //邮箱是否存在
    @Select("select count(1) from sys_user where email=#{email}")
    Long selectByEmail(String email);

    //【除自身】姓名是否存在
    @Select("select count(1) from sys_user where real_name=#{realName} and !id=#{id}")
    Long selectByNameWithoutSelf(@Param("realName") String realName, @Param("id") Long id);

    //【除自身】邮箱是否存在
    @Select("select count(1) from sys_user where email=#{email} and !id=#{id}")
    Long selectByEmailWithoutSelf(@Param("email")String email, @Param("id")Long id);

    //修改用户状态
    @Update("update sys_user set data_state = #{status} where id=#{id}")
    void updateStatus(@Param("id") Long id, @Param("status") String status);

    //用户列表
    List<UserVo> getList(String realName);

    //查询用户状态
    @Select("select data_state from sys_user where id=#{userId}")
    String selectStatus(String userId);

    //初始化用户密码
    @Update("update sys_user set password = #{password} where id=#{userId}")
    void updatePassword(UserPasswordDto userPasswordDto);
}